 <template>
  <div>
    <el-tabs v-model="activeName" @tab-click="changeTab">
      <el-tab-pane
        v-for="(item, index) in tabList"
        :key="index"
        :label="item.lable"
        :name="item.name"
      >
        <ActivateList
          :tableData="tableData"
          :isRecall="isRecall"
          :isReject="item.isReject"
          :isAccept="item.isReject"
          :isDown="item.isDown"
          @accept="accept"
          @reject="reject"
          @down="down"
        ></ActivateList>
      </el-tab-pane>
    </el-tabs>

    <Pagination :total="total" @handleChange="handleChange"/>
  </div>
</template>

<script>
import ActivateList from "./components/activateList.vue";
import { getOrganization } from "api/getData.js";
import { setActivated } from "api/profile.js";
import { formatDateTime } from "src/util/time.js";
import Pagination from "src/components/pagination";

export default {
  data() {
    return {
      activeName: "PENDING",
      tableData: [],
      isRecall: false,
      tabList: [
        {
          name: "PENDING",
          lable: "待处理",
          isReject: true,
          isAccept: true
        },
        {
          name: "REJECTED",
          lable: "已拒绝",
          isDown: true
        },
        {
          name: "PASS",
          lable: "已接受"
        }
      ], //tab标签列表
      currentName: "PENDING", // 当前请求的tab

      total: -1
    };
  },
  components: { ActivateList, Pagination },
  mounted() {
    this.getData("PENDING", 1);
  },
  methods: {
    changeTab(item) {
      this.getData(item.name, 1);
      this.currentName = item.name;
    },
    // 获取数据，待处理，转账中，已处理
    getData(name, pageNumber) {
      getOrganization(pageNumber, name).then(res => {
        this.tableData = res.content.map(item => {
          item.updateTime = formatDateTime(item.updateTime);
          return item;
        });

        this.total = res.totalElements;
      });
    },
    handleChange: function(pageNumber) {
      this.getData(this.currentName, pageNumber);
    },
    // 拒绝转账
    reject(id) {
      this.$prompt("请输入拒绝理由", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消"
      }).then(({ value }) => {
        let data = { remark: value, status: "REJECTED" };
        setActivated(id, data).then(res => {
          this.$message.success("拒绝成功");
          this.getData(this.activeName, 1);
        });
      });
    },
    // 同意转账=》转账中
    accept(id) {
      this.$confirm("确认同意激活吗").then(res => {
        setActivated(id, { status: "PASS" }).then(res => {
          this.$message.success("接受成功");
          this.getData(this.activeName, 1);
        });
      });
    },
    // 提现完成
    down(id) {
      this.$confirm("确认激活已完成吗").then(res => {
        doneOwnerRequest(id).then(res => {
          this.$message.success("激活成功");
          this.getData(this.activeName, 1);
        });
      });
    }
  }
};
</script>

<style lang="scss" scoped>
@import "src/style/mixin";
.tabList {
  @include fj(flex-start);

  .tabItem {
    padding-left: 20px;
  }
}
</style>
